package wms.handler;

import java.text.SimpleDateFormat;
import java.util.Date;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;

import wms.service.dict.DataDictService;
import wms.service.store.StoreSetService;
import wms.service.user.FunctionService;
import wms.service.user.OperatorService;
import wms.util.redis.RedisAPI;

public abstract class BaseController {
	
	protected static Logger log = Logger.getLogger(BaseController.class);
	
	
	@Autowired
	private RedisAPI redisApi;
	
	@Resource
	private OperatorService operatorService;
	
	@Resource
	private FunctionService functionService;
	
	@Resource 
	private DataDictService dataDictService;
	
	@Resource
	private StoreSetService storeSetService;
	
	
	public OperatorService getOperatorService() {
		return operatorService;
	}
	
	public RedisAPI getRedisApi() {
		return redisApi;
	}
	
	public FunctionService getFunctionService() {
		return functionService;
	}
	
	public DataDictService getDataDictService() {
		return dataDictService;
	}
	
	
	public StoreSetService getStoreSetService() {
		return storeSetService;
	}
	
	/**
	 * 日期国际化
	 */
	@InitBinder
	public void init(WebDataBinder dataBinder) {
		log.debug("日期格式化操作..........................");
		dataBinder.registerCustomEditor(Date.class, 
				new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"), true));/*new PropertyEditorSupport(){
			@Override
			public String getAsText() {
				return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format((Date) getValue());
			}
			
			@Override
			public void setAsText(String text) throws IllegalArgumentException {
				try {
					setValue(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(text));
				} catch (ParseException e) {
					e.printStackTrace();
					setValue(null);
				}
			}
		});*/
	}
	
}
